package io.jpress.module.article.directive;

import com.jfinal.aop.Inject;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;
import io.jboot.web.directive.annotation.JFinalDirective;
import io.jboot.web.directive.base.JbootDirectiveBase;
import io.jpress.commons.bean.RenderList;
import io.jpress.module.article.model.ArticleImage;
import io.jpress.module.article.service.ArticleImageService;

import java.util.List;


@JFinalDirective("articleImages")
public class ArticleImagesDirective extends JbootDirectiveBase {

    @Inject
    private ArticleImageService imageService;

    @Override
    public void onRender(Env env, Scope scope, Writer writer) {
        Long articleId = getParaToLong(0, scope);
        List<ArticleImage> articleImages = imageService.findListByArticleId(articleId);
        scope.setLocal("articleImages", new RenderList<>(articleImages));
        renderBody(env, scope, writer);
    }

    @Override
    public boolean hasEnd() {
        return true;
    }
}
